package com.example.demo.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.example.demo.dto.SearchInfo;
import com.example.demo.entity.Patient;



@Repository()
public interface Patient_Mapper extends BaseMapper<Patient>{
	
	@Select("select patient.*,doctor.name doctor_name,nurse.name nurse_name "
			+ " from patient inner join doctor on patient.doctor_id=doctor.id "
			+ " inner join nurse on patient.nurse_id=nurse.id "
			+"${where} ${limitstr}")
	public List<Patient> select(SearchInfo info);
	@Select("select count(1) from patient inner join doctor on patient.doctor_id=doctor.id "
			+ " inner join nurse on patient.nurse_id=nurse.id "
			+"  ${where} ")
	public long selectCount(SearchInfo info);
	
	@Insert("insert into patient (name,sex,age,admission_date,tel,doctor_id,nurse_id) values(#{name},#{sex},#{age},#{admission_date},#{tel},#{doctor_id},#{nurse_id})")
	public void insert (Patient u);
	
	@Update("update patient set name=#{name},sex=#{sex},age=#{age},admission_date=#{admission_date},tel=#{tel},doctor_id=#{doctor_id},nurse_id=#{nurse_id} where id=#{id}")
	public void update (Patient u);
	
	
	@Select("delete from patient where id=#{id}")
	public void delete(int id);
	
	@Select("select * from patient where id=#{id} ")
	public Patient selectById(int id);
	
}
